const app = getApp();
Page({
  data: {
    // name: "xinde",
    // password: "123456",
    name: "",
    password: "",
  },
  onLoad: function (options) {
  },
  // 账号
  _getName(e) {
    var name = e.detail.value;
    this.setData({
      name,
    });
  },
  // 密码
  _getPassword(e) {
    var password = e.detail.value;
    this.setData({
      password,
    });
  },
  // 点击登录
  async toIndex(e) {
    const { name, password } = this.data;
    // 获取首页数据
    let res = await wx.requestAsync({
      url: "login/login",
      data: {
        name,
        password,
      },
    });
    let { user } = res;
    console.log(res);

    if (res.stu == 1) {
      app.globalData.user = user;
      wx.setStorage({
        key:"user",
        data:user
      })
      wx.switchTab({
        url: "/pages/index/index",
      });
    } else {
      wx.showToast({
        title: "登录失败",
        icon:"none",
      });
    }
  },
});
